Open
Conversation
b154a70 to
4f2280e
Compare
src/engraving/dom/instrchange.h
Outdated
| void setInstrument(Instrument* i) | ||
| { | ||
| if (m_instrument != i) { | ||
| delete m_instrument; |
Contributor
There was a problem hiding this comment.
Maybe it would be better to change it to share_ptr?
Contributor
Author
There was a problem hiding this comment.
I assume it would be a more significant change. Maybe it will be the next PR after this is merged.
4f2280e to
770f22b
Compare
770f22b to
dd147c7
Compare
Multiple memory leaks were present in the instrument ownership model: 1. Part destructor: Added destructor to delete all instruments in m_instruments map when Part is destroyed. 2. InstrumentList::setInstrument: Now deletes old instrument pointer before replacing it when the same tick already has an instrument. 3. Part::setInstruments: Now deletes all old instruments before clearing the map and setting new ones. 4. Part::removeInstrument: Now deletes instrument before erasing from map when InstrumentChange elements are removed. 5. Part::removeNonPrimaryInstruments: Now deletes instruments before erasing when removing non-primary instruments. 6. InstrumentChange::setInstrument(Instrument*): Now deletes old instrument pointer before assigning new one (with self-assignment check). 7. ChangeInstrument::cleanup: Added cleanup method to delete the unused instrument pointer after undo/redo operations. These fixes ensure proper memory management throughout the instrument lifecycle and prevent leaks during instrument changes, undo/redo, and Part destruction.
dd147c7 to
722557a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: #32722